
/**
 * @Project : Clion_ProgrammingExercises
 * @File : 0843
 * @Author : WangRuoyu 
 * @Date : 2023/5/21 16:50
 */

#include "iostream"

using namespace std;

const int N = 10;
int st[N][N];
bool loc[N][N];
int dx[] = {-1, 0, 1, 1, 1, 0, -1, -1};
int dy[] = {1, 1, 1, 0, -1, -1, -1, 0};
int n;
int res;

void printGraph() {
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            if (loc[i][j]) printf("Q");
            else printf(".");
        }
        printf("\n");
    }
    printf("\n");
}

void dfs(int k) {
    if (k == n) {
        res++;
        printGraph();
        return;
    }
    for (int i = 0; i < n; ++i) {
        if (st[k][i] == 0) {
            loc[k][i] = true;
            st[k][i]++;
            for (int j = 0; j < 8; ++j) {
                int p = k + dx[j], q = i + dy[j];
                while (p >= 0 && p < n && q >= 0 && q < n) {
                    st[p][q]++;
                    p += dx[j];
                    q += dy[j];
                }
            }

            dfs(k + 1);

            loc[k][i] = false;
            st[k][i]--;
            for (int j = 0; j < 8; ++j) {
                int p = k + dx[j], q = i + dy[j];
                while (p >= 0 && p < n && q >= 0 && q < n) {
                    st[p][q]--;
                    p += dx[j];
                    q += dy[j];
                }
            }
        }
    }
}

int main() {
    scanf("%d", &n);

    dfs(0);

    return 0;
}